#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  untitled.py
#  
#  Copyright 2012 Aleksi Joakim Palomäki <aleksi@Oblivion>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  

import sys, commands
#try:
 #	import pygtk
  #	pygtk.require("2.0")
#except:
 # 	pass
try:
	import gtk
  	import gtk.glade
except:
	sys.exit(1)
print "Imported stuff successfully."
class  FiWeatherGUI:

    def __init__(self):
        self.gladefile = "gui_simple1.glade"
        self.builder = gtk.Builder()
        self.builder.add_from_file(self.gladefile)
        self.builder.connect_signals(self)
        #self.builder.get_object("window1")
        self.window = self.builder.get_object("window1")
        self.button1 = self.builder.get_object("button1")
        self.entry = self.builder.get_object("entry1")
        self.text = self.builder.get_object("textview1")
        
        if (self.window):
                self.window.connect("destroy", gtk.main_quit)
                self.button1.connect("clicked", self.btnclicked)

    def btnclicked(self, widget):
        #print "You clicked the button1"
        city = self.entry.get_text()
        weatherinfo = commands.getoutput("python fiweather " + city)
        #help(self.text)
       # print     self.text.get_buffer().insert(self.text.get_buffer().get_end_iter(),  "\n" + str(weatherinfo))  
        print self.text.get_buffer().set_text(str(weatherinfo))
app = FiWeatherGUI()
gtk.main()
